package Merlion.SCM.entity;

import Merlion.CRM.entity.PricebookEntity;
import Merlion.MRP.entity.MonthlySalesRecordEntity;
import java.util.Collection;
import java.util.List;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import Merlion.MRP.entity.BillOfMaterialsEntity;

@Entity
@DiscriminatorValue(value = "FIN")
public class ProductEntity extends InventoryEntity {

    private double caseWeight; // in kg
    private double basePrice;
    private int productionRate; // no of cases produced per hour
    @OneToMany(mappedBy = "item")
    private Collection<InventoryBatchEntity> productBatches;
    @OneToMany(mappedBy = "product")
    private List<MonthlySalesRecordEntity> monthlySalesRecords;
    @OneToMany
    private List<PricebookEntity> pricebook;
    private double listPrice;
    private double limitPrice;

    public double getCaseWeight() {
        return caseWeight;
    }

    public void setCaseWeight(double caseWeight) {
        this.caseWeight = caseWeight;
    }

    public double getBasePrice() {
        return basePrice;
    }

    public void setBasePrice(double basePrice) {
        this.basePrice = basePrice;
    }

    public Collection<InventoryBatchEntity> getProductBatches() {
        return productBatches;
    }

    public void setProductBatches(Collection<InventoryBatchEntity> productBatches) {
        this.productBatches = productBatches;
    }

    public BillOfMaterialsEntity getBOMEntity() {
        return BOMEntity;
    }

    public void setBOMEntity(Merlion.MRP.entity.BillOfMaterialsEntity BOMEntity) {
        this.BOMEntity = BOMEntity;
    }
    @OneToOne
    private BillOfMaterialsEntity BOMEntity;

    public ProductEntity() {
        this.inventoryType = "FIN";
    }

    public ProductEntity(String name, String description, int shelfLife, double caseWeight, double basePrice, int productionRate) {
        this.name = name;
        this.description = description;
        this.shelfLife = shelfLife;
        this.caseWeight = caseWeight;
        this.basePrice = basePrice;
        this.productionRate = productionRate;
        this.inventoryType = "FIN";
    }

    public ProductEntity(String name, String description, int shelfLife, double caseWeight, double basePrice,
            int productionRate, double listPrice, double limitPrice) {
        this.setName(name);
        this.setDescription(description);
        this.setShelfLife(shelfLife);
        this.setCaseWeight(caseWeight);
        this.setBasePrice(basePrice);
        this.setProductionRate(productionRate);
        this.setInventoryType("FIN");
        this.setLimitPrice(limitPrice);
        this.setListPrice(listPrice);

    }

    public int getProductionRate() {
        return productionRate;
    }

    public void setProductionRate(int productionRate) {
        this.productionRate = productionRate;
    }

    public List<MonthlySalesRecordEntity> getMonthlySalesRecords() {

        monthlySalesRecords.size();

        return monthlySalesRecords;


    }

    public void setMonthlySalesRecords(List<MonthlySalesRecordEntity> monthlySalesRecords) {
        this.monthlySalesRecords = monthlySalesRecords;
    }

    public List<PricebookEntity> getPricebook() {
        System.out.println(pricebook.size());
        return pricebook;
    }

    public void setPricebook(List<PricebookEntity> pricebook) {
        this.pricebook = pricebook;
    }

    public double getLimitPrice() {
        return limitPrice;
    }

    public void setLimitPrice(double limitPrice) {
        this.limitPrice = limitPrice;
    }

    public double getListPrice() {
        return listPrice;
    }

    public void setListPrice(double listPrice) {
        this.listPrice = listPrice;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ProductEntity)) {
            return false;
        }
        ProductEntity other = (ProductEntity) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "mrp.ProductEntity[ id=" + id + " ]";
    }
}
